package net.tngou.c4j.ml;

import net.tngou.crawler.pojo.Ml;

/**
 * 训练
 * @author tngou@tngou.net
 *
 */
public class Train {

	public static void Study(Model model) {
		Ml ml= new Ml().get("keyword='"+model.getKey()+"'");
		Study(model,ml);
	}
	/**
	 * 学习
	 * @param model
	 * @param ml
	 */
	public static void Study(Model model,Ml ml) {
		if(ml==null) {
			//新建
			ml=new Ml();
			ml.setKeyword(model.getKey());;
			ml.save();
		}
			
		ml.setType(model.getType());
		ml.setIsnull(model.getIsnull());
		if(ml.getMinlength()==0)ml.setMinlength(model.getLength());
		if(model.getLength()<ml.getMinlength())
			ml.setMinlength(model.getLength());
		if(model.getLength()>ml.getMaxlength())
			ml.setMaxlength(model.getLength());
		if(ml.getMinword()==0)ml.setMinword(model.getWord());
		if(model.getWord()<ml.getMinword())
			ml.setMinword(model.getWord());
		if(model.getFilterword()>ml.getFilterword())
			ml.setFilterword(model.getFilterword());
		ml.setCount(ml.getCount()+1);
		ml.update();//更新
	}
}
